<template>
    <div class="headtop">
        <div class="headbody" v-if="business.id">
            <div>
                <van-image width="5rem" height="5rem" fit="cover" radius="1.2rem" :src="business.avatar_text" />
            </div>
            <div>
                <p class="">{{ business.username }}</p>
                <p class="">账号：{{ business.usernumber }}</p>
                <p class="">会员：{{ business.vipendtime_text }}</p>

            </div>
        </div>

        <div class="headbody" v-else>

            <div>
                <van-image width="6rem" height="6rem" fit="cover" radius="1.2rem"
                    src="http://www.schoolwall.com/assets/img/avatar.png" />
            </div>
            <div>
                <p id="login" @click="login()">点击登录</p>
            </div>
        </div>
    </div>

    <div class="vipbody">
        <label v-for="(item, index) in vip" :key="index" :for="item.id" @click="num(item.id)">
            <input type="radio" name="vip" :id="item.id" v-model="money" :value="'￥' + item.money" hidden>

            <div class="viplist" :class="{ 'chek': nums === item.id }">
                <p>{{ item.name }}</p>
                <p><span>￥</span>{{ item.money }}</p>
                <p>原价<span>{{ Math.ceil(item.money * item.id) }}</span></p>

                <p>套餐{{ item.id }}</p>
            </div>
        </label>
    </div>

    <p class="p1">温馨提示：支付过程中遇到问题，请前往用户中心</p>
    <button class="sub" @click="submit">{{ money }}开通套餐{{ nums }}</button>

    <Tabbar ref="tabbarRef" />
</template>

<script setup>
import { onMounted, ref } from 'vue';

const { proxy } = getCurrentInstance();
const business = ref(proxy.$business.value)

const vip = ref([])
const money = ref('')
const nums = ref('')

// 选择套餐
const num = (id) => {
    nums.value = id;
}

// 挂载
onMounted(() => {
    getViplist()
})

// 获取vip列表
const getViplist = async () => {
    const res = await proxy.$http.post({
        url: '/vip/getviplist',
        params: {
            id: null
        }
    })

    if (res.code === 1) {
        vip.value = res.data.viplist
    } else {
        proxy.$fail(res.msg)
    }
}

// 提交
const submit = async () => {
    // 如果登录信息不存在就提示用户登录
    if (!business.value.id) {
        proxy.$fail('请先登录')
        // 定时跳转登录页面
        setTimeout(() => {
            proxy.$router.push('/login')
        }, 1000)
        return
    } else if (!nums.value) {
        proxy.$fail('请选择套餐')
        return
    }

    // 组装后端需要数据
    const data = {
        busid: business.value.id,
        vipid: nums.value
    }

    const res = await proxy.$http.post({
        url: '/vip/buyvip',
        params: data
    })

    if (res.code === 1) {
        proxy.$success('下单成功，准备前往支付')
        // 定时跳转支付页面
        setTimeout(() => {
            proxy.$router.push({
                path: '/pay/page',
                query: {
                    id: nums.value
                }
            })
        }, 1000)
    } else {
        proxy.$fail(res.msg)
    }
}

// 登录
const login = () => {
    proxy.$router.push('/login')
}



</script>

<style scoped>
* {
    margin: 0;
    padding: 0;
}

.headtop {
    width: 100%;
    height: 8rem;
    background-color: rgb(25, 25, 25);
    /* 超出部分隐藏 */
    overflow: hidden;
    /* 处理bug */
    margin-bottom: 0.5rem;
}

.headbody {
    display: flex;
    width: 100%;
    height: 5rem;
    margin-top: 1.5rem;
}

.headbody div {
    margin-left: 0.5rem;
}

.headbody div>p:nth-child(1) {
    font-size: 1.3rem;
    line-height: 2rem;
    /* 缩进 */
    text-indent: 0.8rem;
    /* 字间距 */
    letter-spacing: 0.1rem;
    color: white;
}

.headbody div>p:nth-child(2) {
    font-size: 1rem;
    line-height: 2rem;
    text-indent: 0.8rem;
    color: aliceblue;
}

.headbody div>p:nth-child(3) {
    font-size: 0.8rem;
    line-height: 1rem;
    text-indent: 0.8rem;
    color: aliceblue;
}


#login {
    text-decoration: underline;
    margin-top: 50%;
    transform: translateY(-50%);
    font-size: 1.7rem;
    opacity: 0.7;
}


#login:hover {
    color: purple;
}


.vipbody {
    width: 100%;
    display: flex;
    /* 换行 */
    flex-wrap: wrap;
    justify-content: space-around;
}

.viplist {
    width: 180px;
    height: 240px;
    background-color: rgba(255, 255, 255, 0.1);
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    position: relative;
}

.viplist>p:nth-child(4) {
    position: absolute;
    top: 0;
    left: 0;
    background-color: rgba(255, 255, 255, 0.1);
    font-size: 1.3rem;
    border-radius: 5px;
    padding: 5px 10px;
    background-color: #ff4243;
}

.viplist>p:nth-child(1) {
    font-size: 1.5rem;
    color: #eed79a;
}

.viplist>p:nth-child(2) {
    font-size: 3rem;
    color: #ffe6a5;
    font-weight: 700;
    margin-top: 20px;
}

.viplist>p:nth-child(2) span {
    font-size: 1.5rem;
}

.viplist>p:nth-child(3) {
    font-size: 1.2rem;
    color: #776c4c;
    margin-top: 20px;
    font-weight: 600;
    /* 删除线 */
    text-decoration: line-through;
}

.sub {
    width: 80%;
    height: 50px;
    background-color: #ffe5a4;
    color: #111111;
    font-size: 1.3rem;
    border-radius: 10px;
    margin-top: 20px;
    margin-bottom: 8rem;
    font-weight: 600;
    display: block;
    margin-left: auto;
    margin-right: auto;
}

.chek {
    transition: all 0.2s;
    transform: scale(1.1);
    background-color: rgba(51, 46, 33);
    position: relative;
    z-index: 1;
}


/* 媒体查询，在电脑模式下 */
@media screen and (min-width: 1024px) {
    .viplist {
        width: 280px;
        height: 360px;
    }

    /* 鼠标移上去变大一点倍然后背景颜色变化来个黑色边框 */
    .viplist:hover {
        transition: all 0.5s;
        transform: scale(1.1);
        background-color: rgba(51, 46, 33);
        position: relative;
        z-index: 1;
    }

    /* 选中的套餐的样式 */
    input:checked+.viplist {
        transform: scale(1.1);
        background-color: rgba(51, 46, 33);
        position: relative;
        z-index: 1;
    }

    .submit:hover {
        background-color: #ffd77a;
    }

    .sub:hover {
        background-color: #ffd77a;
    }
}
.p1 {
    text-indent: 1rem;
    margin: 1.5rem 0;
    background: linear-gradient(90deg,
            rgba(209, 64, 64, 0.8),
            rgba(117, 250, 255, 0.9),
            rgba(255, 77, 181, 0.8));
    background-size: 300% auto;
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 0 2px 4px rgba(255, 77, 181, 0.2);
    animation: gradientMove 8s ease infinite;
}

@keyframes gradientMove {
    0% {
        background-position: 0% center;
        text-shadow: 0 2px 4px rgb(250, 71, 71);
    }

    50% {
        background-position: 100% center;
        text-shadow: 0 3px 6px rgb(93, 188, 243);
    }

    100% {
        background-position: 0% center;
        text-shadow: 0 2px 4px rgba(244, 70, 171, 0.2);
    }
}
</style>
